<form id="addOrUpdateForm" lay-filter="addOrUpdateForm" class="layui-form model-form">

    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">排班日期</label>
        <div class="layui-input-block">
            <input type="text" name="scheduleDate" id="scheduleDateId" placeholder="请选择排班日期" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">维修人员</label>
        <div class="layui-input-block">
            <select name="technicianName">
                <option value="">请选择维修工</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">工作时段</label>
        <div class="layui-input-block">
            <select name="workShift">
                <option value="">请选择时段</option>
                <option value="上午">上午</option>
                <option value="下午">下午</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">工作内容</label>
        <div class="layui-input-block">
            <input name="workContent" class="layui-input" placeholder="请输入工作内容" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">目标楼层</label>
        <div class="layui-input-block">
            <input name="target" class="layui-input" placeholder="请输入目标楼层" lay-verType="tips" lay-verify="required|number" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">维修地点</label>
        <div class="layui-input-block">
            <input name="place" class="layui-input" placeholder="请输入维修地点" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="formSubmitBtn" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'form', 'admin', 'xnUtil', 'xmSelect', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var xnUtil = layui.xnUtil;
        var xmSelect = layui.xmSelect;
        var laydate = layui.laydate;

        form.render();

        laydate.render({
            elem: '#scheduleDateId'
        });

        var editData = admin.getLayerData('#addOrUpdateForm').data;
        if(editData !== null && editData !== undefined) {
            $("[name='workContent']").val(editData.remarks);

            //form.val('addOrUpdateForm', editData);
        }

        //发送请求获取空闲员工
        admin.req(getProjectUrl() + 'echnician/page?state=1&status=在职', function(res){
            console.log(res.data);
            for (var i=0; i<res.data.length; i++){
                var str = ' <option value="' + res.data[i].name + '">' + res.data[i].name + ' (空闲)' + '</option>';
                $("[name='technicianName']").append(str);
                form.render('select');
            }
        }, 'get');



        /**
         * 表单提交事件
         */
        form.on('submit(formSubmitBtn)', function (data) {
            layer.load(2);

            console.log(data.field);

            var url =  getProjectUrl() + 'repairSchedule/add';
            admin.req(url, JSON.stringify(data.field), function(res){
                layer.msg(res.message, {icon: 1, time: 1000}, function () {
                    admin.putLayerData('formOk', true, '#addOrUpdateForm');
                    admin.closeDialog('#addOrUpdateForm');
                });
            }, 'post');
            var url1 =  getProjectUrl() + 'repair/edit' ;
            data.field.status = 2;
            data.field.id = editData.id;
            admin.req(url1, JSON.stringify(data.field), function(res){
/*                layer.msg(res.message, {icon: 1, time: 1000}, function () {
                    admin.putLayerData('formOk', true, '#addOrUpdateForm');
                    admin.closeDialog('#addOrUpdateForm');
                });*/
            }, 'post');
            return false;
        });
    });
</script>
</body>
</html>
